package com.ddwl.gate.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.gate.service.DingTalkService;
import com.ddwl.gate.util.RobotHelperUtil;
import com.ddwl.schema.bo.gate.DingTalkBo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 钉钉消息推送
 * @author wenbin
 */
@Api(tags = "dingding推送接口")
@RequestMapping("/dingding")
@RestController
public class DingTalkController extends BaseController {
    
    @Resource
    private RobotHelperUtil robotHelperUtil;

    @Resource
    private DingTalkService dingTalkService;

    @PostMapping("/dingTalkMessageRobot")
    @ApiOperation("钉钉推送(钉钉机器人)")
    public RestVo dingTalkMessage(@RequestParam("message") String message,@RequestParam("mobiles") String mobiles) {
        dingTalkService.sendMessage(message,mobiles);
        return RestVo.ok();
    }

    @GetMapping("/dingTalkMessageDept")
    @ApiOperation("钉钉推送(按部门)")
    public RestVo sendDingTalkMessageDept(@RequestParam("message") String message,@RequestParam("departments") String departments) throws Exception{
        List<String> departmentsList= Arrays.asList(departments.split(","));
        dingTalkService.sendMessageDept(message,departmentsList);
        return RestVo.ok();
    }

    @GetMapping("/dingTalkMessageMobiles")
    @ApiOperation("钉钉推送(按电话)")
    public RestVo sendDingTalkMessageMobiles(@RequestParam("message") String message,@RequestParam("mobiles") String mobiles) throws Exception{
        mobiles="13429652329";
        List<String> mobilesList= Arrays.asList(mobiles.split(","));
        dingTalkService.sendMessageMobile(message,mobilesList);
        return RestVo.ok();
    }

    @PostMapping("/dingTalkMessageNow")
    @ApiOperation("钉钉即时推送")
    public RestVo sendDingTalkMessageNow(@RequestBody DingTalkBo pagebo) throws Exception{
        dingTalkService.sendMessageNow(pagebo);
        return RestVo.ok();
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        dingTalkService.changeId();
        return RestVo.ok();
    }
}
